#pragma once

#include <context.hpp>
#include "detector/detector.hpp"
#include "tracker/tracker.hpp"

class Vision {
public:
	Vision(Detector* detector, Tracker* tracker, cv::Size stdSize = cv::Size(2,2), double retargetOnSpeed = RETARGET_ON_SPEED);
	~Vision(){};
	void capture(cv::Mat& frame);
	bool spot();

	cv::Rect  target;
	cv::Size  stdSize;
	double    retargetOnSpeed;
	int       dx;
	int       dy;
	double    ds;
	double    dz;
	int       trackingDeltaX;
	int       trackingDeltaY;
	double    trackingDeltaS;
	std::vector<cv::Rect> detectionResults;
	cv::Rect  mostCenteredDetectionResult;
	cv::Rect  lastTrackingResult;
	cv::Rect  thisTrackingResult;

protected:
	cv::Mat frame;
	int width, height;
	float halfWidth, halfHeight;
	
	Detector* detector;
	Tracker*  tracker;

	double    tmp_ds;
	double    min_ds;
	bool      isLost;
	
	double geometricalDistance(int x, int y);
	void manualRetargetMouseHandler(int event, int x, int y, int flags, void *param);
};
